<template>
  <div>
    <h1>路由</h1>
    <button @click="toAbout">跳转</button>
    <button @click="to">跳转</button>
  </div>
</template>

<script>
import { useRouter } from 'vue-router'
export default {
  // 不可以访问this  => undefined
  setup() {
    //  获取路由 router类似于 vue2 this.$router
    const router = useRouter()

    const to = () => {
      router.push('/about')
    }


    return {
      to
    }

  },
  methods: {
    toAbout() {
      this.$router.push('/about')
    }
  }
}
</script>